package li.tmi.TxBtry;

import android.content.Context;
import android.content.SharedPreferences;


public class TxPref {

	public static String PREFS_NAME_TXBTRY = "TxBtryPref";
	public static String BTRYLEVEL = "TxBtryLevel";
	public static String BTRYCLEVEL = "TxBtryCurrentLevel";
	public static String BTRYPLUG = "TxBtryPlug";
	public static String BTRYTIME = "TxBtryTime";
	public static String BTRYRTIME = "TxBtryRTime";
	private String PREFS_NAME;
	
	public TxPref(String _PREFS_NAME) {
		PREFS_NAME = _PREFS_NAME;
	}
	
	

	
	public void saveBtryMisc(Context context, int id, String what, String value) {
		SharedPreferences.Editor prefs = context.getSharedPreferences(PREFS_NAME, 0).edit();
		prefs.putString(PREFS_NAME+id+what, value);
		prefs.commit();
	}
	
	public String getBtryMisc(Context context, int id, String what) {
		SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, 0);
        String prefix = prefs.getString(PREFS_NAME+id+what, null);    
        if(prefix != null) {
        	return prefix;     	
        }else {
        	return null;
        }
	}

	
	//function called when a Widget is deleted from the homescreen
	public void deletePreAndId(Context context, int id){
		deleteMisc(context, id);
	}
	
	private void deleteMisc(Context context, int id) {
		SharedPreferences.Editor prefs = context.getSharedPreferences(PREFS_NAME, 0).edit();
		prefs.remove(PREFS_NAME+id+TxPref.BTRYLEVEL);
		prefs.remove(PREFS_NAME+id+TxPref.BTRYPLUG);
		prefs.remove(PREFS_NAME+id+TxPref.BTRYTIME);
		prefs.remove(PREFS_NAME+id+TxPref.BTRYRTIME);
		prefs.remove(PREFS_NAME+id+TxPref.BTRYCLEVEL);
		prefs.commit();
	}
	
	
	
	
	
}
